"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHtmlTemplate = exports.getEntry = exports.getAliases = exports.SRC_FILE = exports.resolveApp = exports.appDirectory = void 0;
var fs_1 = require("fs");
var path_1 = require("path");
exports.appDirectory = (0, fs_1.realpathSync)(process.cwd());
var resolveApp = function (relativePath) {
    return (0, path_1.resolve)(exports.appDirectory, relativePath);
};
exports.resolveApp = resolveApp;
exports.SRC_FILE = (0, exports.resolveApp)("src");
var getAliases = function (path) {
    if (path === void 0) { path = exports.SRC_FILE; }
    var alias = {};
    var files = (0, fs_1.readdirSync)(path);
    files.forEach(function (item) {
        var paths = (0, path_1.resolve)(path, item);
        var stat = (0, fs_1.lstatSync)(paths);
        if (stat.isDirectory() === true) {
            alias["@".concat(item)] = paths;
        }
    });
    return __assign({ "@": path }, alias);
};
exports.getAliases = getAliases;
var getEntry = function () {
    var e_1, _a, e_2, _b;
    var entry = "";
    try {
        for (var _c = __values([
            "index",
            "Index",
            "src/index",
            "src/Index",
            "main",
            "Main",
            "src/main",
            "src/Main",
        ]), _d = _c.next(); !_d.done; _d = _c.next()) {
            var name_1 = _d.value;
            try {
                for (var _e = (e_2 = void 0, __values([".js", ".ts", ".jsx", ".tsx"])), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var ext = _f.value;
                    entry = (0, path_1.resolve)(name_1 + ext);
                    if ((0, fs_1.existsSync)(entry)) {
                        return entry;
                    }
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
                }
                finally { if (e_2) throw e_2.error; }
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return "";
};
exports.getEntry = getEntry;
var getHtmlTemplate = function () {
    var e_3, _a, e_4, _b;
    try {
        for (var _c = __values([
            "index",
            "public/index",
            "src/index",
            "src/public/index",
            "assets/index",
            "src/assets/index",
        ]), _d = _c.next(); !_d.done; _d = _c.next()) {
            var name_2 = _d.value;
            try {
                for (var _e = (e_4 = void 0, __values([".html", "htm"])), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var ext = _f.value;
                    var template = (0, path_1.resolve)(name_2 + ext);
                    if ((0, fs_1.existsSync)(template)) {
                        return template;
                    }
                }
            }
            catch (e_4_1) { e_4 = { error: e_4_1 }; }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
                }
                finally { if (e_4) throw e_4.error; }
            }
        }
    }
    catch (e_3_1) { e_3 = { error: e_3_1 }; }
    finally {
        try {
            if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
        }
        finally { if (e_3) throw e_3.error; }
    }
    return "";
};
exports.getHtmlTemplate = getHtmlTemplate;
